package com.winsdom.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.winsdom.context.BaseContext;
import com.winsdom.dto.CategoryTreeNodesParent;
import com.winsdom.dto.UnclearedDTO;
import com.winsdom.dto.resource.BillsPageQueryReqDTO;
import com.winsdom.entity.Bills;
import com.winsdom.entity.Category;
import com.winsdom.mapper.BillsMapper;
import com.winsdom.mapper.CategoryMapper;
import com.winsdom.result.PageResult;
import com.winsdom.service.IBillsService;
import com.winsdom.vo.BillDetailsVO;
import com.winsdom.vo.UnclearedVO;
import com.winsdom.vo.resource.BillsNotArrearsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 账单表 服务实现类
 * </p>
 *
 * @author 
 * @since 2025-05-22
 */
@Service
public class BillsServiceImpl extends ServiceImpl<BillsMapper, Bills> implements IBillsService {
    @Autowired
    private BillsMapper billsMapper;
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public PageResult getUnclearedBills(UnclearedDTO unclearedDTO) {
        Page<UnclearedVO> page = new Page<>(unclearedDTO.getCurrentPage(), unclearedDTO.getPageSize());
        List<UnclearedVO> records = billsMapper.findUnclearedBills(page, unclearedDTO, BaseContext.getCurrentId(),"11111111");
        PageResult pageResult = new PageResult();
        pageResult.setPageNum(unclearedDTO.getCurrentPage());
        pageResult.setPageSize(unclearedDTO.getPageSize());
        pageResult.setTotal(page.getTotal());
        pageResult.setRecords(records);
        return pageResult;
    }

    @Override
    public Page<BillsNotArrearsVO> selectArrearsListForParams(Integer pageNum, Integer pageSize, BillsPageQueryReqDTO billsPageQueryReqDTO) {
        return billsMapper.selectArrearsListForParams(new Page<>(pageNum,pageSize),billsPageQueryReqDTO);
    }
    @Override
    public BillDetailsVO getBillDetails(Long billsId) {
        BillDetailsVO billDetailsVO = billsMapper.getBillDetails(billsId);
        Long category = billsMapper.findCategoryId(billsId);
        CategoryTreeNodesParent categoryTreeNodesParent = categoryMapper.getRootTree(category);
        System.out.println(categoryTreeNodesParent);
        billDetailsVO.setCategoryTreeNodes(categoryTreeNodesParent);
        return billDetailsVO;
    }

}
